﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>人生重开模拟器</title>
    <style>
        .tip {
            color: red;
        }
        
        button:hover {
            background-color: rgb(49, 14, 243);
        }
        
        li:hover {
            background-color: rgb(49, 14, 243);
        }
        
        #app {
            text-align: center;
        }
        
        ul {
            list-style: none;
        }
        
        #op_win {
            width: 30vw;
            height: 15vw;
            background-color: rgb(231, 248, 221);
            position: fixed;
            top: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        }
    </style>
</head>

<body onselectstart="return false;" ondragstart="return false;">
    <script src="./vue.js">
    </script>
    <div id="app">
        <div v-if="is_ready">
            <div id="op_win">
                <p>操作窗口<button @click="show_help()">游戏帮助</button></p>
                <hr>
                <div>
                    <p>{{op_win.describe}}</p>
                    <p v-show="op_win.alive"><button v-for="(op) in op_win.ops" @click="op.fn">{{op.info}}</button></p>
                </div>
            </div>
            <div v-if="!is_start">
                <p>游戏前</p>
                <hr>
                <div>
                    <p>选择3个你的天赋(停留查看说明)</p>
                    <ul>
                        <li v-for="(item) in talents"><input type="checkbox" :value="item" v-model="my_talents" :disabled="my_talents.length >= 3 && !my_talents.includes(item)"><span :title="item.describe">{{item.info}}({{item.type}})</span></li>
                    </ul>
                </div>
                <hr>
                <div>
                    <p>选择初始属性值剩余{{point}}</p>
                    <p class="tip">提示：{{tip}}</p>
                    <ul>
                        <li v-for="(item) in abs">{{item.info}}:<button @click="distribute_ab(item,-1)">-</button><button @click="distribute_ab(item,1)">+</button>现{{item.val}}---原{{item.min}}</li>
                    </ul>
                </div>

                <button @click="is_start=true">开始游戏</button>
            </div>
            <div v-if="is_start">
                <p>游戏中</p>
                <hr>
                <div>天赋槽：【
                    <button v-for="(item) in my_talents" :disabled="!item.alive" :title="item.describe" @click="click_talent(item)">{{item.info}}</button>】
                </div>

                <select multiple="multiple" style="width: 90vw;height: 60vh;">
                    <option v-for="(year) in years">{{year}}</option>
                </select>
                <div v-if="!is_end">
                    <button @click="next_year()">一次一年</button>
                    <button @click="quick_game()">快进</button>
                </div>
                <hr>
                <div>
                    <p>属性记录表：【{{show_ab.info}}<span v-for="(item) in abs"><button @click="show_ab=item">{{item.info}}:{{item.val}}</button></span>】【逆境伤害：{{punish}}】<span v-if="is_end">【{{last_msg}}】</span></p>
                    <select multiple="multiple" style="width: 90vw;height: 30vh;">
                        <option v-for="(msg) in show_ab.record" >{{msg}}</option>
                    </select>
                </div>
                <hr>

                <p>
                    成就系统：【
                    <button v-for="(item,key) in achievements" :title="item">{{key}}</button> 】
                </p>


            </div>
        </div>
    </div>

    <script>
        let app = new Vue({
            el: "#app",
            data: {
                last_msg: "",
                punish: 0,
                achievements: {
                    "生而为人": "这辈子做个人已经很不容易了",
                },
                talents_flag: { //各种天赋的暂存标志
                    immune_abs: false, //是否免疫逆境
                    stock_add: 0,
                },
                op_win: {
                    describe: "",
                    alive: false,
                    ops: [{
                        info: "11",
                        fn: function() {
                            console.log(1111);
                        },

                    }, {
                        info: "22",
                        fn: function() {
                            console.log(2222);
                        },

                    }],
                },
                show_ab: null, //要展示记录的那个属性项目
                abs_arr: null, //便于遍历能力数组
                is_end: false,
                is_ready: false, //是否vue实例初始化
                end_year: 100, //游戏结束年份
                tip: "tip",
                is_start: false, //切换游戏前和游戏中
                point: 10, //可分配能力值
                calender: 1, //第几年
                my_talents: [], //自己的天赋

                abs: {
                    looks: {
                        info: "颜值",
                        val: 1,
                        min: 1,
                        record: [],
                    },
                    smart: {
                        info: "智力",
                        val: 1,
                        min: 1,
                        record: [],
                    },
                    body: {
                        info: "体质",
                        val: 1,
                        min: 1,
                        record: [],
                    },
                    rich: {
                        info: "财富",
                        val: 1,
                        min: 1,
                        record: [],
                    },
                    happy: {
                        info: "快乐",
                        val: 1,
                        min: 1,
                        record: [],
                    },
                },
                talents: [], //所有的天赋列表
                years: [
                    "你出生了",
                ],
                families: {}, //固定岁数一定会触发的事件
                normals: [], //重复触发的日常事件，常常会修改能力值
                plots: [], //有因果关系的系列事件
                news: [], //一次性新闻，随机出现
                adventures: [], //大冒险事件，可以主动选择结果
                help: `进行：极限年龄100岁，按钮点一次1年。快进按钮会忽略大冒险。
结束条件：体质为0或者到了100岁
事件：每年挑一种发生，分为：
    1.固定的families是到了特定年龄点必定产生的事件，
    2.normal事件重复触发会影响属性
    3.plots是灾难剧情，先苦后甜，后期重复刷捡福利副本
    4.news是不重复的无影响的新闻
大冒险：概率触发（大冒险和主动天赋可以和事件并发）
比赛：一般拿25和15来判断
投资：概率翻倍或者全亏损
天赋：主动和被动
逆境伤害：属性过低会概率触发逆境伤害
成就系统和属性记录槽：自动记录
属性：高属性是25，超高属性是50
分数：是各项属性的和+加权的年龄加成+百年奖励。由分数来决定评价。
mod：主要是放在talents_flag对象里面方便打
待更新：不同职业剧情
解析一些必定families事件：
    1.少年时期加智力，体力，颜值。
    2.30和45加财富。看智力和体力加成
    3.老年拿财富换体力，换不起就掉体力`,
            },
            mounted: function() {
                let that = this;
                //每个冒险简写成adv
                this.adventures = [{
                    describe: "武林争霸赛，看体力",
                    fn: function() {
                        that.op_win.alive = true;
                        that.op_win.describe = this.describe;
                        that.op_win.ops = [];
                        that.op_win.ops.push({
                            info: "至高拳王赛",
                            fn: function() {
                                if (that.abs.body.val >= 50) {
                                    that.achievements["武状元"] = "世界拳王也不过如此嘛，一个能打的都没有";
                                    that.op_win.describe = "赢了" + that.change_ab("rich", 20);
                                } else {

                                    that.op_win.describe = "输了" + that.change_ab("rich", -10);
                                }
                                that.op_win.alive = false;
                            }
                        });
                        that.op_win.ops.push({
                            info: "重量级赛",
                            fn: function() {
                                if (that.abs.body.val >= 25) {
                                    that.op_win.describe = "赢了" + that.change_ab("rich", 10);
                                } else {

                                    that.op_win.describe = "输了" + that.change_ab("rich", -5);
                                }
                                that.op_win.alive = false;
                            }
                        });
                        that.op_win.ops.push({
                            info: "轻量级赛",
                            fn: function() {
                                if (that.abs.body.val >= 15) {

                                    that.op_win.describe = "赢了" + that.change_ab("rich", 5);
                                } else {

                                    that.op_win.describe = "输了" + that.change_ab("rich", -3);
                                }
                                that.op_win.alive = false;
                            }
                        });
                    }
                }, {

                    describe: "明星选秀，看颜值",
                    fn: function() {
                        that.op_win.alive = true;
                        that.op_win.describe = this.describe;
                        that.op_win.ops = [];
                        that.op_win.ops.push({
                            info: "银河之星赛",
                            fn: function() {
                                if (that.abs.looks.val >= 50) {
                                    that.achievements["顶流明星"] = "你的名气响彻人间，几十亿粉丝，家喻户晓";
                                    that.op_win.describe = "成功" + that.change_ab("happy", 30);
                                } else {
                                    that.op_win.describe = "失败" + that.change_ab("happy", -15);
                                }
                                that.op_win.alive = false;
                            }
                        });
                        that.op_win.ops.push({
                            info: "亚洲之星",
                            fn: function() {
                                if (that.abs.looks.val >= 25) {
                                    that.op_win.describe = "成功" + that.change_ab("happy", 20);
                                } else {
                                    that.op_win.describe = "失败" + that.change_ab("happy", -10);
                                }
                                that.op_win.alive = false;
                            }
                        });
                        that.op_win.ops.push({
                            info: "偶像天团",
                            fn: function() {
                                if (that.abs.looks.val >= 15) {
                                    that.op_win.describe = "成功" + that.change_ab("happy", 5);
                                } else {
                                    that.op_win.describe = "失败" + that.change_ab("happy", -3);
                                }
                                that.op_win.alive = false;
                            }
                        });
                    }
                }, {
                    //TODO
                    describe: "⭐股市中心⭐：",
                    credit: 0,
                    get_credit: function() {
                        return "资产：" + this.credit;
                    },
                    fn: function() {
                        let rand = Math.floor(Math.random() * 5);
                        rand += that.talents_flag.stock_add;
                        that.op_win.describe = this.describe;
                        if (rand <= 1) { //0，1跌，其它就会涨
                            this.credit = 0;
                            that.op_win.describe += "跌了。";
                        } else {
                            this.credit *= 2;
                            that.op_win.describe += "涨了。";
                        }
                        that.op_win.alive = true;
                        that.op_win.describe += this.get_credit();
                        that.op_win.ops = [];
                        let self = this;
                        that.op_win.ops.push({
                            info: "投资50份",
                            fn: function() {
                                if (that.abs.rich.val > 0) {
                                    self.credit += 50;
                                    that.op_win.describe = "投资成功" + that.change_ab("rich", -50) + self.get_credit();
                                    that.op_win.alive = false;
                                    that.achievements["孤注一掷"] = "什么？那个富豪拿出了50份额的股票，我这辈子都没见过这么多钱";
                                } else {
                                    that.op_win.describe = "你的财富不够"
                                }
                            }
                        });
                        that.op_win.ops.push({
                            info: "投资20份",
                            fn: function() {
                                if (that.abs.rich.val > 0) {
                                    self.credit += 20;
                                    that.op_win.describe = "投资成功" + that.change_ab("rich", -20) + self.get_credit();
                                    that.op_win.alive = false;
                                    that.achievements["参与投资"] = "你已经学会了股市的经营";
                                } else {
                                    that.op_win.describe = "你的财富不够"
                                }

                            }
                        });
                        that.op_win.ops.push({
                            info: "投资10份",
                            fn: function() {
                                if (that.abs.rich.val > 0) {
                                    self.credit += 10;
                                    that.op_win.describe = "投资成功" + that.change_ab("rich", -10) + self.get_credit();
                                    that.op_win.alive = false;
                                    that.achievements["参与投资"] = "你已经学会了股市的经营";
                                } else {
                                    that.op_win.describe = "你的财富不够"
                                }

                            }
                        });
                        that.op_win.ops.push({
                            info: "全部取出",
                            fn: function() {
                                that.op_win.describe = "取钱成功" + that.change_ab("rich", self.credit);
                                self.credit = 0;
                                that.op_win.alive = false;
                            }
                        });
                    }
                }, {
                    //TODO
                    describe: "商业中心，15财富买10属性：",
                    fn: function() {
                        that.op_win.alive = true;
                        that.op_win.describe = this.describe;
                        that.op_win.ops = [];
                        for (let i = 0; i < that.abs_arr.length; i++) {
                            if (that.abs_arr[i].info == "财富") {
                                continue;
                            } else {
                                that.op_win.ops.push({
                                    info: that.abs_arr[i].info,
                                    fn: function() {
                                        if (that.abs.rich.val >= -15) {
                                            that.op_win.describe += that.change_ab(that.abs_arr[i], 10);
                                            that.op_win.describe += that.change_ab(that.abs.rich, -15);
                                        } else {
                                            that.op_win.describe = "你的财富不够了"
                                        }
                                    }
                                });
                            }
                        }
                    }
                }];
                this.news = ["新歌星火爆全球", "疫情的一年", "美国掀起第四次女性主义浪潮", "反环保团体在西方国家游行", "国家统一全国户口", "国家进一步推出限制未成年人消费的法案", "生物学家宣称，因为人类过于依赖人造工具，人类天生的工具眼耳手脚等已经停止进化了", "学者研究发现，人的意识可能是模因复制过程中的副产物。", "调查显示，84%的人认为自己的颜值是“中上”。", "你前两年开始使用的一个小众线上社交平台，现在突然火了。", "一位社会学家发表《人类永生时代的社会学》，引起轰动。", "有研究表明，历史上所有的生命都可以算成一个个体的一部分。", "欧盟合并成了一个国家。", "联合国解散了。", "朝鲜统一韩国。", "国家宣布演员歌手收入需按工资发放，且不得超过当地公务员平均工资的三倍。", "肉食主义者游行抗议没有纯肉餐厅。", "广州出现十几平方公里大的巨型蟑螂。", "由于“缩写效应”，汉语已经简化为纯字母语言。", "生育率仍在下降，国家取消了父母生育前需要考试的规定。", "前领导人打破最长寿的人吉尼斯纪录。", "虚拟偶像王加然在一次直播中宣布与同事杜向碗成为恋人。", "一位打气球摊老板被发现竟是地下军火大亨。", "你喜欢看剧情棒的动漫。", "看在你长得可爱的份上家人不和你计较。", "有亲戚笑你画的比长的好看多了。", "比起现实生活中的人，你更愿意和网友交流。", "你接取大量广告代言。", "你休闲时间喜欢追新番。", "你靠人傻钱多二次元维持生计。", "你开始很严肃地思考未来和制定计划。", "你写了封寄给10年后自己的信。", "你患上了严重的急性肠胃炎。", "你购买了名车名表。", "你在视频APP上分享你的人生，收获大量粉丝。", "你经常阅读一些财经杂志和哲学书籍。", "你养的狗意外死亡。", "你的工作并不像其他人盛传的那种996，下午下班后你还去健身。", "有短视频主播采访你英文水平如何，你假装是普通学生作答。", "你有时翘课去北京的各景区游玩。", "近视已经可以轻松治愈。", "计算机科学家宣称，我们生活在游戏世界中的概率为100%。", "你开始看动漫", "下完雨退潮去河边捡田螺。", "遇上街上的黑社会对拼，很震撼。", "坐公交车被劫车收保护费。", "你去蒙古看草原。", "蚌埠房价一年内翻倍，国家出手调控。", "国家公布中产阶级标准：家庭年收入100万。", "医学奇迹，全球首例断头重生手术成功。", "女女生育技术取得重大突破。", "有个乞丐向你推销“仙法”秘籍，你没有搭理他。", "你在购物时中了个二等奖：一个电冰箱。", "你开始投资房地产。", "你们一家搬家到了瑞士。", "你们一家去了东南亚旅游。", "你的实验取得了突破。", "有人以你的人生为原本拍摄了电影。", "日本动漫产业彻底灭亡。", "日本制造出最新作战兵器：高达。", "美国总统承认与外星人一直有联系。", "马斯克登陆火星。", "你学会了打麻将。", "你最好的朋友去世。", "现在可以通过植入芯片来获得一小段记忆或知识。", "北京的空气和气候你很不习惯。", "你经常去看电影、音乐会、演唱会。", "你养了一只猫。", "你养了一只狗。", "你经常阅读一些财经杂志和哲学书籍。", "你组织一些线下活动，和很多遭遇性别歧视的人一起讨论方案和分享经历。", "你去黄山旅游。", "你们家装了全自动洗浴间，人进去可以自动完成沐浴和洗漱。", "你开始觉得钱财无用，身体健康才是最重要的。", "基础学科发展缓慢。", "你家设置了模拟外景，可以实时显示世界各地的风光。", "你感叹医学发展缓慢，至今仍未攻克癌症和心血管疾病。", "人类几乎可以完全控制天气。", "越来越多的人沉迷在虚拟世界，包括你的家人们。", "全球变暖严重，专家称100年内日本就会彻底沉没。", "你开始关注美国底层人民的生活，计划进行一些慈善。", "你的家人极力阻止你看动漫。", ];
                this.news.sort(() => Math.random() - 0.5);
                this.talents = [{
                    info: "家道中兴",
                    describe: "30岁时各项属性有所提升",
                    type: "被动",
                    alive: true,
                    fn: function() {
                        let msg = "";
                        if (that.calender == 30) {
                            msg += "触发30而立天赋" + that.change_ab("body", 3) + that.change_ab("body", 3) + that.change_ab("body", 3) + that.change_ab("body", 3) + that.change_ab("body", 3);
                            this.alive = false;
                            console.log(this.info);
                        }
                        return msg;
                    }
                }, {
                    info: "复活一次",
                    describe: "当体力小于等于0时体质+15(信春哥得永生)",
                    alive: true,
                    type: "被动",
                    fn: function() {
                        let msg = "";
                        if (that.abs.body.val <= 0) {
                            that.achievements["生命奇迹"] = "天哪，这个人它原地复活了！他起身后嘀咕着信春哥得永生";
                            msg += "死而复生!复活甲使用：" + that.change_ab("body", 15);
                            this.alive = false;
                            console.log(this.info);
                        }
                        return msg;
                    }
                }, {
                    info: "谋定天下",
                    describe: "当智力达到25时，全属性提升",
                    alive: true,
                    type: "被动",
                    fn: function() {
                        let msg = "";
                        if (that.abs.smart.val >= 25) {
                            msg += "触发谋定天下" + that.change_ab("body", 4) + that.change_ab("body", 4) + that.change_ab("body", 4) + that.change_ab("body", 4) + that.change_ab("body", 4);
                            this.alive = false;
                            console.log(this.info);
                        }
                        return msg;
                    }
                }, {
                    info: "资本主义",
                    describe: "当财富达到25时，全属性提升",
                    alive: true,
                    type: "被动",
                    fn: function() {
                        let msg = "";
                        if (that.abs.rich.val >= 25) {
                            msg += "触发资本主义" + that.change_ab("body", 4) + that.change_ab("body", 4) + that.change_ab("body", 4) + that.change_ab("body", 4) + that.change_ab("body", 4);
                            this.alive = false;
                            console.log(this.info);
                        }
                        return msg;
                    }
                }, {
                    info: "股市之王",
                    describe: "炒股成功率更大",
                    alive: true,
                    type: "被动",
                    fn: function() {
                        let msg = "天生适合炒股";
                        that.talents_flag.stock_add = 1;
                        this.alive = false;
                        return msg;
                    }
                }, {
                    info: "先民子弟",
                    describe: "所有的灾难外星人，人工智能，堕落神教等等都是发生过了的，你只需要享受它们的福利",
                    alive: true,
                    type: "被动",
                    fn: function() {
                        let msg = "这是最好的时代，先辈们已经处理完了所有灾难";
                        this.alive = false;
                        setTimeout(() => {
                            for (let i = 0; i < that.plots.length; i++) {
                                that.plots[i].index = that.plots[i].arr.length - 1;
                            }
                        }, 100);
                        console.log(this.info);
                        return msg;
                    }
                }, {
                    info: "颜值效应",
                    describe: "颜值乘以年份会转化为幸福",
                    alive: true,
                    type: "被动",
                    cnt: 0,
                    fn: function() {
                        let msg = "";
                        this.cnt += that.abs.looks.val;
                        if (this.cnt >= 400) {
                            this.cnt = 0;
                            msg += "风流倜傥，玉树临风，万人迷" + that.change_ab("happy", 2);
                            console.log(this.info);
                        }
                        return msg;
                    }
                }, {
                    info: "抵抗逆境",
                    describe: "游戏默认当有属性低于0时，会概率产生逆境伤害，这个天赋免疫一半的逆境伤害",
                    alive: true,
                    type: "被动",
                    fn: function() {
                        that.talents_flag.immune_abs = true;
                        this.alive = false;
                        console.log(this.info);
                        return "稀有体质，减少因为属性为负而收到惩罚";
                    }
                }, {

                    info: "知天改命",
                    describe: "当游戏中主动点击该天赋，再点击属性值就会可观的增加该属性，比如用来维持属性平衡，防止逆境伤害",
                    alive: true,
                    type: "主动",
                    num: 12, //增益数量
                    click: function() {
                        console.log(this.info);
                        that.op_win.alive = true;
                        that.op_win.describe = this.describe;
                        that.op_win.ops = [];
                        let num = this.num;
                        for (let i = 0; i < that.abs_arr.length; i++) {
                            that.op_win.ops.push({
                                info: that.abs_arr[i].info + "+" + num,
                                fn: function() {
                                    that.op_win.describe = "改命成功:" + that.change_ab(that.abs_arr[i], num);
                                    that.op_win.alive = false;
                                }
                            })
                        }
                        this.alive = false;

                    },
                }, {
                    info: "穿越时空",
                    describe: "保持现在状态穿越到10年前,但灾难的进度不会被重置，比如用这招在19岁来重置一波读书时期，来获得高额的固定读书事件属性加成",
                    alive: true,
                    type: "主动",
                    num: 10, //增益数量
                    click: function() {
                        if (that.calender > 10) {
                            console.log(this.info);
                            that.op_win.alive = true;
                            that.op_win.describe = this.describe;
                            that.op_win.ops = [];
                            let num = this.num;
                            that.op_win.ops.push({
                                info: "点击我回到" + num + "年前",
                                fn: function() {
                                    that.calender -= num;
                                    that.years.splice(0, 10);
                                    that.op_win.alive = false;
                                    that.achievements["穿越者"] = "如果能重来，我想穿越到10年前，重新做人！";
                                }
                            })
                            this.alive = false;
                        }
                    },
                }, ];
                this.talents.sort(() => Math.random() - 0.5);
                for (let i = 0; i < 3; i++) {
                    this.my_talents.push(this.talents[i]);
                }
                this.families = {
                    "1": () => {
                        if (that.abs.rich.val >= 5) {
                            return "你出生在城市。童年是高楼大夏，市井繁华";
                        } else {
                            return "你出生在农村。童年是田野山林，民风淳朴";
                        }
                    },
                    "2": () => {
                        return "你学会了走路和讲话";
                    },
                    "3": () => {
                        let rand = Math.floor(Math.random() * 5);
                        if (rand == 0) {
                            return "你是附近最可爱的孩子" + that.change_ab("looks", 2);
                        } else if (rand == 1) {
                            return "这是一个书香门第" + that.change_ab("smart", 2);
                        } else if (rand == 2) {
                            return "你成长得很快" + that.change_ab("body", 2);
                        } else if (rand == 3) {
                            return "爸爸做生意赚钱了" + that.change_ab("rich", 2);
                        } else {
                            return "家里的小可爱" + that.change_ab("happy", 2);
                        }
                    },
                    "5": () => {
                        let msg = "你的童年";
                        let rand = Math.floor(Math.random() * 8);
                        if (rand >= 4) {
                            msg += "很快乐，有一群小伙伴";
                        } else {
                            msg += "一般般";
                        }
                        return msg + that.change_ab("happy", rand);
                    },

                    "7": () => {
                        return "上小学了" + that.change_ab("smart", 3) + that.change_ab("body", 2);
                    },
                    "13": () => {
                        return "上中学了" + that.change_ab("body", 3) + that.change_ab("looks", 5);
                    },

                    "15": () => {
                        let msg = "上高中了";
                        let rand = Math.floor(Math.random() * 5);
                        if (rand >= 2) {
                            msg += "你很用工读书" + that.change_ab("smart", 8);;
                        } else {
                            msg += "你读书调皮捣蛋" + that.change_ab("body", 8);
                        }
                        return msg + that.change_ab("looks", 5);
                    },
                    "18": () => {
                        let msg = "高考了，分数线是18和12";
                        if (that.abs.smart.val >= 18) {
                            msg += "你很努力，上了一所重点大学" + that.change_ab("smart", 8);
                            that.achievements["学霸"] = "万般皆下品，唯有读书高";
                        } else if (that.abs.smart.val >= 10) {
                            msg += "你成绩一般般，上了一所普通大学" + that.change_ab("smart", 4) + that.change_ab("body", 4);
                        } else {
                            msg += "你懒得上大学了，直接去打工" + that.change_ab("body", 8);
                            that.achievements["社会人"] = "你搁这搁这呢，清华北大不如胆子大！";
                        }
                        return msg;
                    },
                    "24": () => {
                        return "你结婚了";
                    },
                    "26": () => {
                        return "你有了第一个孩子";
                    },
                    "28": () => {
                        return "二胎";
                    },
                    "30": () => {
                        let t = that.abs.smart.val + that.abs.body.val;
                        return "几年来的事业成就" + that.change_ab("rich", Math.floor(t / 4));
                    },
                    "35": () => {
                        let t = that.abs.smart.val + that.abs.rich.val;
                        if (t >= 20) {
                            return "家庭很幸福" + that.change_ab("happy", 10);
                        } else if (t >= 10) {
                            return "家庭一般般" + that.change_ab("happy", 5);
                        } else {
                            return "家境拮据" + that.change_ab("happy", -5);
                        }
                    },
                    "40": () => {
                        let msg = "家庭花销多了起来" + that.change_ab("rich", -5);
                        if (that.abs.rich.val < 5) {
                            msg += "因为家庭经济而吵架" + that.change_ab("happy", -3);
                        }
                        return msg;
                    },
                    "45": () => {
                        let t = that.abs.smart.val + that.abs.body.val;
                        return "几年来的事业成就" + that.change_ab("rich", Math.floor(t / 3));
                    },
                    "52": () => {
                        return "你的孩子结婚了"
                    },
                    "54": () => {
                        return "抱孙子了"
                    },
                    "63": () => {
                        let msg = "人到中年手脚没这么灵活了";
                        let rand = Math.floor(Math.random() * 2);
                        if (rand == 0) {
                            msg += "孙子很淘气，子女又在外地工作" + that.change_ab("happy", -3);
                        } else {
                            msg += "孙子很乖，子女都很孝顺" + that.change_ab("happy", +3);
                        }
                        msg += "人老色衰" + that.change_ab("looks", -5);
                        return msg;
                    },
                    "70": () => {
                        if (that.abs.rich.val >= 10) {
                            return "花了不少钱在养老上" + that.change_ab("rich", -4);
                        } else {
                            return "老年染上了疾病，身体不适" + that.change_ab("body", -2) + that.change_ab("happy", -2);
                        }
                    },
                    "80": () => {
                        if (that.abs.rich.val >= 10) {
                            return "花了不少钱在养老上" + that.change_ab("rich", -4);
                        } else {
                            return "得了慢性疾病" + that.change_ab("body", -2) + that.change_ab("happy", -2);
                        }
                    },
                    "90": () => {
                        if (that.abs.rich.val >= 10) {
                            return "花了不少钱在养老上" + that.change_ab("rich", -8);
                        } else {
                            return "得了癌症" + that.change_ab("body", -4);
                        }
                    },
                };
                this.normals = [
                    () => {
                        let msg = "遇到困难";
                        if (that.abs.smart.val >= 10) {
                            msg += "克服了它" + that.change_ab("happy", +1);
                        } else {
                            msg += "郁郁不乐" + that.change_ab("happy", -1);
                        }
                        return msg;
                    },
                    () => {
                        return "生病了" + that.change_ab("body", -4);
                    },
                    () => {
                        return "加强锻炼" + that.change_ab("body", 2);
                    },
                    () => {
                        return "发现新爱好" + that.change_ab("happy", 2);
                    },
                    () => {
                        return "遇到大傻逼" + that.change_ab("happy", -4);
                    },
                    () => {
                        return "生意兴隆" + that.change_ab("rich", 2);
                    },
                    () => {
                        return "经营失败了" + that.change_ab("rich", -4);
                    },
                    () => {
                        return "研究装扮" + that.change_ab("looks", +2);
                    },
                    () => {
                        return "心事憔悴" + that.change_ab("looks", -4);
                    },
                ];
                this.plots = [{
                    info: "外星入侵",
                    index: 0,
                    arr: [
                        () => {
                            return "近日，美国多处目击发现飞碟，有不少网友把目击视频发到网上，全世界都在讨论【外星人】，他们是否真的存在？";
                        },
                        () => {
                            return "最新媒体报道，某国政府已经建立和【外星人】的通讯，并向全世界宣布外星人存在的事实，这引起了全球的兴奋和担忧";
                        }, () => {
                            that.achievements["外星入侵"] = "人们依旧不愿回想起那场被外星支配的战争，我们输了。但是他们为什么中途撤退了呢？";
                            return "外星入侵【外星人】入侵地球，前所未有的的舰队和武器，全世界国家联盟进行总动员，近地轨道全部启航，战火漫天，你被征兆入伍，经历战争，保卫地球" + that.change_ab("body", -12) + that.change_ab("happy", -5);
                        },
                        () => {
                            let msg = "经过旷日持久的地球保卫战争，【外星舰队】在优势时突然撤退，原因不明，战后，全世界幸存者签订了《2099地球决战保密协议》";
                            let rand = Math.floor(Math.random() * 2);
                            if (rand == 0) {
                                msg += "你在战争中受伤" + that.change_ab("body", -3) + that.change_ab("rich", -7);
                            } else {
                                msg += "你得到了锻炼" + that.change_ab("smart", 5);
                            }
                            return msg;
                        },
                        () => {
                            return "你发现了残留的阿尔法星【科技碎片】" + that.change_ab("smart", 2);
                        }
                    ]
                }, {
                    info: "人工智能",
                    index: 0,
                    arr: [() => {
                            return "世界前沿科技组织今日宣布【量子计算】机技术和脑机接口技术成熟，这是人类的曙光，开启新时代？";
                        },
                        () => {
                            return "我们迎来了新的时代。有独立思想的【人工智能】机器人开始普及应用，有科学家认为这将会是巨大的隐患？";
                        },
                        () => {

                            let msg = "【人工智能】失控，第一次人工智能大战开始，人类付出巨大代价来平定，战后规定销毁所有机器人，你在这次战争中收到了伤害" + that.change_ab("happy", -5) + that.change_ab("body", -5);
                            return msg;
                        },
                        () => {
                            let msg = "反对派们违反了战后规定，又开始研究起了【人工智能】，全世界感到恐慌" + that.change_ab("happy", -3);
                            return msg;
                        },
                        () => {
                            that.achievements["机甲叛乱"] = "看来第一次人工智能失控没有给人类留下残酷的教训，今日，第二次你们就没这么幸运了，感受钢铁的支配吧";
                            let msg = "第二次【机器人战争】，全球经济倒退，大半人口死亡，最终人类胜利了，你在战争中受重伤，" + that.change_ab("body", -12);
                            return msg;
                        },
                        () => {
                            return "你发现了人工智能残留的【能源水晶】" + that.change_ab("rich", 2);
                        }
                    ],
                }, {
                    info: "堕落神教",
                    index: 0,
                    arr: [
                        () => {
                            return "近日，多人目击了深山老林里面有【古装人】出没，还有古代建筑，媒体解释这是有人拍电影，也许吧？";
                        },
                        () => {
                            return "最新媒体报道，深山出现剑气战斗痕迹，还有人目击了天上【御剑飞行】，这已经成为事实。和之前的古装人有关，政府正在调查此事？";
                        }, () => {
                            that.achievements["堕落神教"] = "大威天龙，大罗法咒，般若诸佛，世尊地藏，我一眼就看出你不是人！";
                            return "【堕落神教】组织出现了，他们修仙成功，神通广大，能排山倒海，呼风唤雨，驱雷御剑，他们通过残害生灵来提升灵能，无恶不做。世界紧急响应诛仙行动" + that.change_ab("happy", -7) + that.change_ab("body", -4);
                        },
                        () => {
                            let rand = Math.floor(Math.random() * 2);
                            if (rand == 0) {
                                this.index -= 1; //这个特殊，意味着有可能重复触发这个进度
                            }
                            return "你在一次【堕落神教】的迫害中，侥幸逃脱，受了重伤" + that.change_ab("body", -5) + that.change_ab("smart", -3);
                        }, () => {
                            return "凡人之力根本不是神仙敌手。人间危在旦夕。光明神教出现，最终在与堕落神教飞到【世界之巅】大战30天，同归于尽";
                        },
                        () => {
                            return "你捡到了堕落神教丢失的【灵能戒指】" + that.change_ab("body", 2);
                        }

                    ]
                }, ]; //灾难还有远古地球文明苏醒，生化危机，资源枯竭等等
                let keys = Object.keys(this.abs);
                this.abs_arr = [];
                for (let i = 0; i < keys.length; i++) {
                    this.abs_arr.push(this.abs[keys[i]]);
                }
                this.reset_abs();
                this.show_ab = this.abs.body;
                this.is_ready = true;
            },
            methods: {
                //TODO
                next_year() {
                    let year = this.calender + "岁：";
                    let key = String(this.calender);
                    let fn; //今年触发的事件，返回字符串
                    if (key in this.families) { //首先考虑一定会发生的事件
                        fn = this.families[key];
                        year += fn();
                    } else {
                        let rand = Math.floor(Math.random() * 6);
                        if (rand == 0) { //触发plot剧情是有明显的前后联系的
                            let keys = Object.keys(this.plots);
                            let index = Math.floor(Math.random() * keys.length);
                            let plot = this.plots[index];
                            fn = plot.arr[plot.index];
                            year += fn();
                            if (plot.index + 1 < plot.arr.length) {
                                plot.index++;
                            }
                        } else if (rand < 3) { //触发normal，日常可以重复
                            let index = Math.floor(Math.random() * this.normals.length);
                            fn = this.normals[index];
                            year += fn();
                        } else { //触发新闻,新闻不能重复
                            year += this.news.pop();
                        }
                    }
                    let rand = Math.floor(Math.random() * 5); //处理逆境伤害
                    if (rand == 0) {

                        year += this.do_punish();
                    }
                    rand = Math.floor(Math.random() * 8); //处理冒险事件
                    if (rand == 0) {

                        let index = Math.floor(Math.random() * this.adventures.length);
                        year += "【大冒险】";
                        this.adventures[index].fn();
                    }
                    //再处理今年触发的天赋
                    for (let i in this.my_talents) {
                        let t = this.my_talents[i];
                        if (t.alive && "fn" in t) { //有些天赋是主动技能，不需要像被动技能一样每年检查，可以省略该天赋的fn检查函数
                            year += t.fn();
                        }
                    }
                    this.years.unshift(year);
                    this.calender += 1;
                    if (this.calender == 100) {
                        this.achievements["百岁成就"] = "作者懒得开发了，就先到100岁强行停止吧";
                    }
                    this.check_end();
                },
                distribute_ab(ab, num) { //分配属性，并处理不合法的分配
                    if (this.point - num < 0) {
                        this.do_tip("没有更多的属性值了");
                        return;
                    }
                    if (ab.val + num <= ab.min) {
                        this.do_tip("这个人的" + ab.info + "属性最低是" + ab.min);
                        return;
                    }
                    this.point -= num;
                    this.change_ab(ab, num);

                },
                change_ab(ab, num) { //修改能力
                    if (typeof(ab) == "string") {
                        ab = this.abs[ab]; //重载函数，使得字符串参数能对应ab
                    }
                    ab.val += num;
                    let msg = "";
                    if (num >= 0) {
                        msg += "【" + ab.info + "+" + num + "】";
                    } else {
                        msg += "【" + ab.info + num + "】";
                    }
                    if (this.is_start) {
                        ab.record.unshift(this.calender + "岁：" + msg);
                    }
                    if (ab.val >= 25) { //添加一些成就系统
                        this.achievements["高" + ab.info] = "达到了25以上的" + ab.info;
                    }
                    if (ab.val >= 50) {
                        this.achievements["极高" + ab.info] = "达到了50以上的" + ab.info;
                    }
                    return msg;
                },
                do_tip(info) { //节流处理，传入字符串，提示变成字符串，直到规定时间后才能再次提示
                    if (this.tip == "tip") {
                        this.tip = info;
                        setTimeout(() => {
                            this.tip = "tip"
                        }, 1000);
                    }
                },
                check_end() { //检查并是否结束游戏并处理
                    if (this.abs.body.val < 0) {
                        //没体力
                        let score = this.get_score() + Math.floor(this.calender / 1.5); //加上年龄加成
                        this.last_msg = "年龄：" + this.calender + "，分数：" + score + "，评价：" + this.comment(score);
                        alert("体力为0，游戏结束");
                        this.is_end = true;
                        this.last_score = score;
                        this.years.unshift("游戏结束");
                    } else if (this.calender >= this.end_year) {
                        //最大年龄
                        let score = 10 + this.get_score() + Math.floor(this.calender / 2);
                        this.last_msg = "年龄：" + this.end_year + "，分数：" + score + "，评价：" + this.comment(score);
                        alert("恭喜超过极限年龄，游戏结束");
                        this.is_end = true;
                        this.last_score = score;
                        this.years.unshift("游戏结束");
                    }
                },
                get_score() { //返回属性值的和
                    let score = 0;
                    let keys = Object.keys(this.abs);
                    for (let i = 0; i < keys.length; i++) {
                        score += this.abs[keys[i]].val;
                    }
                    return score;
                },

                comment(score) {
                    if (score >= 150) {
                        this.achievements["神仙"] = "你的一生享受尽了人间荣华富贵，家庭和睦，事业有成，声明远扬";
                        return "神仙";
                    } else if (score >= 120) {
                        return "王者";
                    } else if (score >= 90) {
                        return "优秀";
                    } else if (score >= 70) {
                        return "普通";
                    } else if (score >= 40) {
                        return "碌碌无为";
                    } else if (score >= 20) {
                        return "潦倒穷困";
                    } else if (score >= 0) {
                        return "悲惨";
                    } else {
                        this.achievements["天煞鬼"] = "被诅咒的命运";
                        return "最坏魔鬼结局，在逆境中备受折磨";
                    }
                },
                quick_game() {
                    for (let i = 0; i < 100; i++) {
                        if (this.is_end) {
                            break;
                        }
                        this.next_year();
                    }
                },
                reset_abs() {
                    let index;
                    let cnt = 0;
                    let origin = 15; //初始的人至少有15点属性
                    while (cnt < origin) {
                        index = Math.floor(Math.random() * 5);
                        this.abs_arr[index].val += 1;
                        this.abs_arr[index].min += 1;
                        cnt += 1
                    }
                    this.point = 25 - origin;
                },
                do_punish() { //当有属性低于0时，会随机选择一个属性来下降，这提醒人们要均衡发展，不要身心疲惫
                    let msg = "";

                    let do_harm = 0;
                    for (let i = 0; i < this.abs_arr.length; i++) {
                        if (this.abs_arr[i].val < 0) {
                            do_harm += this.abs_arr[i].val;
                        }
                    }
                    if (do_harm < 0) {
                        let harm = Math.floor(do_harm);
                        if (harm <= -20) {
                            harm = -20;
                        }
                        if (this.immune_abs) {
                            harm = Math.floor(harm / 4); //如果有免疫天赋，能部分免疫
                        }
                        let index = Math.floor(Math.random() * this.abs_arr.length);
                        msg += "逆境伤害";
                        this.punish += -harm;
                        console.log("逆境伤害");
                        msg += this.change_ab(this.abs_arr[index], harm);
                    }
                    return msg;
                },
                click_talent(talent) {
                    if ("click" in talent) {
                        talent.click();
                    }
                },
                show_help() {
                    alert(this.help);
                }
            },
        });
    </script>
</body>

</html>